<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#div1{
				width:100px;
				height:100px;
				background: red;
				position:absolute;
				top:100px;
				left:100px;
			}
		</style>
	</head>
	<body>
		<script>
			window.onload = function(){
				var btn = document.getElementsByTagName('input')[0];
				var oDiv = document.getElementById('div1');
				var timer = null;
//				单击事件 onclick
				btn.onclick = function(){
					move(oDiv,5,500);
				}
				
				function move(obj,speed,target){

					clearInterval(timer);
					
					timer = setInterval(function(){
						var oldLeft = obj.offsetLeft;
						var newLeft = oldLeft + speed;
						if(newLeft>target){
							clearInterval(timer);
							newLeft = target;
						}
						obj.style.left = newLeft + 'px';
					},1000/60);
				}
			}
		</script>
		<input type="button" value="动起来" />
		<div id="div1">11</div>
	</body>
</html>
